//
//  error_exit.cpp
//  learnC++
//
//  Created by apple on 2018/6/1.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "error_exit.hpp"

int getArrayValue(const std::array<int, 10> &array, int index)
{
    // use if statement to detect violated assumption
    if (index < 0 || index >= array.size())
        exit(2); // terminate program and return error number 2 to OS
    
    return array[index];
}

void printString(const char *cstring)
{
    // Only print if cstring is non-null
    if (cstring)
        std::cout << cstring;
    else
        std::cerr << "function printString() received a null parameter";
}

void test_error_exit(){
    
    //多检查
    printString(nullptr);
    
}

